﻿<%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="PagePhanQuyenByModule.aspx.cs"
    Inherits="Viewer.ChucNang.PagePhanQuyenByModule" %>

<%@ Register Src="UserControls/NhomQuyenByModule.ascx" TagName="NhomQuyenByModule"
    TagPrefix="uc1" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../resources/css/main.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        var grdNhomQuyenByModule_Command = function(command, record) {
            if (command == 'Detail') {
                X.ShowDialog_QUNhomQuyenByModule_Detail(record.id);
                return;
            }

            if (command == 'Edit') {
                X.ShowDialog_NhomQuyenByMoDule_Edit(record.id);
                return;
            }

            if (command == 'Delete') {
                Ext.MessageBox.show({
                    title: 'Confirm',
                    msg: 'Bạn có chắc chắn xóa record này ko?',
                    icon: Ext.MessageBox.QUESTION,
                    buttons: Ext.MessageBox.YESNO,
                    fn: function(btn) {
                        if (btn.toLowerCase() == 'yes') {
                            X.NhomQuyenByToChuc_Delete(record.id);
                        }
                    }
                });
            }

        }

        var applyFilter = function(grid) {
            var store = grid.getStore();
            store.suspendEvents();
            store.filterBy(getRecordFilter());
            store.resumeEvents();
            grid.getView().refresh(false);
        };

        var getRecordFilter = function() {
            var f = [];

            f.push({
                filter: function(record) {
                    return filterString(txtFilter1.getValue(), "TenNhomQuyenByModule", record);
                }
            });

            var len = f.length;

            return function(record) {
                for (var i = 0; i < len; i++) {
                    if (!f[i].filter(record)) {
                        return false;
                    }
                }
                return true;
            };

        };
        var filterString = function(value, dataIndex, record) {
            var val = record.get(dataIndex);

            if (typeof val != "string") {
                return value.length == 0;
            }

            return val.toLowerCase().indexOf(value.toLowerCase()) > -1;
        };
        var showTip = function() {
            var rowIndex = grdNhomQuyen.view.findRowIndex(this.triggerElement),
                cellIndex = grdNhomQuyen.view.findCellIndex(this.triggerElement),
                record = storeNhomQuyenByModule.getAt(rowIndex),
                fieldName = grdNhomQuyen.getColumnModel().getDataIndex(cellIndex),
                data = record.get(fieldName);

            this.body.dom.innerHTML = data;
        }
    </script>

</head>
<body style="background-color: White;">
    <form id="form1" runat="server">
    <ext:ResourceManager Locale="vi" ID="ResourceManager1" runat="server" DirectMethodNamespace="X">
        <Listeners>
            <DocumentReady Handler="Ext.net.DirectEvent.timeout = 360000;" />
            <AjaxRequestException Handler="Ext.net.Mask.hide();" />
            <BeforeAjaxRequest Handler="Ext.net.Mask.show();" />
            <AjaxRequestComplete Handler="Ext.net.Mask.hide();" />
        </Listeners>
    </ext:ResourceManager>
    <div style="padding-top: 5px; padding-left: 5px; padding-right: 5px;">
        <ext:Panel ID="tabNhomQuyenByModule" runat="server" Layout="Fit" MonitorResize="true"
            Border="false">
            <Items>
                <ext:GridPanel ID="grdNhomQuyen" runat="server" Height="555" AutoExpandColumn="TenNhomQuyen"
                    StripeRows="true">
                    <TopBar>
                        <ext:Toolbar ID="Toolbar1" runat="server">
                            <Items>
                                <ext:TriggerField ID="txtFilter1" runat="server" EnableKeyEvents="true" EmptyText="Tìm kiếm">
                                    <Triggers>
                                        <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                    </Triggers>
                                    <Listeners>
                                        <KeyUp Handler="this.triggers[0].show();applyFilter(#{grdNhomQuyen});" Buffer="350" />
                                        <TriggerClick Handler="this.setValue(''); this.triggers[0].hide(); #{storeNhomQuyenByModule}.clearFilter();" />
                                    </Listeners>
                                </ext:TriggerField>
                                <ext:Button ID="btnAddNewNhomQuyenByModule" runat="server" Text="Tạo Mới" Icon="Add">
                                    <DirectEvents>
                                        <Click OnEvent="ShowDialog_NhomQuyenByModule_AddNew" />
                                    </DirectEvents>
                                </ext:Button>
                            </Items>
                        </ext:Toolbar>
                    </TopBar>
                    <BottomBar>
                        <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageIndex="1" PageSize="20"
                            HideRefresh="true">
                        </ext:PagingToolbar>
                    </BottomBar>
                    <ColumnModel>
                        <Columns>
                            <ext:CommandColumn Width="50">
                                <Commands>
                                    <ext:SplitCommand>
                                        <Menu>
                                            <Items>
                                                <ext:MenuCommand Text="Chi Tiết" CommandName="Detail" Icon="LayoutHeader">
                                                </ext:MenuCommand>
                                                <ext:MenuCommand Text="Sửa" CommandName="Edit" Icon="ApplicationEdit">
                                                </ext:MenuCommand>
                                                <ext:MenuCommand Text="Xóa" CommandName="Delete" Icon="Delete">
                                                </ext:MenuCommand>
                                            </Items>
                                        </Menu>
                                    </ext:SplitCommand>
                                </Commands>
                            </ext:CommandColumn>
                            <ext:Column DataIndex="TenNhomQuyenByModule" Header="Tên Nhóm Quyền (Chức Năng) "
                                Width="200">
                            </ext:Column>
                            <ext:Column DataIndex="TenNhomQuyen" Header="Tên Module">
                            </ext:Column>
                            <ext:Column DataIndex="TenUserOwner" Header="Người Dùng Chịu Trách Nhiệm " Width="100">
                            </ext:Column>
                            <ext:Column DataIndex="GhiChu" Header="Ghi Chú">
                            </ext:Column>
                        </Columns>
                    </ColumnModel>
                    <SelectionModel>
                        <ext:RowSelectionModel runat="server">
                        </ext:RowSelectionModel>
                    </SelectionModel>
                    <Store>
                        <ext:Store ID="storeNhomQuyenByModule" runat="server">
                            <Reader>
                                <ext:JsonReader IDProperty="NhomQuyenByModuleID">
                                    <Fields>
                                        <ext:RecordField Name="TenNhomQuyenByModule">
                                        </ext:RecordField>
                                        <ext:RecordField Name="TenNhomQuyen">
                                        </ext:RecordField>
                                        <ext:RecordField Name="UserIDOwner" />
                                        <ext:RecordField Name="TenUserOwner" />                                        
                                        <ext:RecordField Name="GhiChu">
                                        </ext:RecordField>
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <Listeners>
                        <Command Handler="grdNhomQuyenByModule_Command(command,record);" />
                    </Listeners>
                    <View>
                        <ext:GridView ID="GridView" runat="server" ForceFit="true" />
                    </View>
                </ext:GridPanel>
            </Items>
        </ext:Panel>
        <ext:ToolTip ID="RowTip" runat="server" Target="={grdNhomQuyen.getView().mainBody}"
            Delegate=".x-grid3-cell" TrackMouse="true">
            <Listeners>
                <Show Fn="showTip" />
            </Listeners>
        </ext:ToolTip>
        <uc1:NhomQuyenByModule ID="ucNhomQuyenByModule" runat="server" />
    </div>
    </form>
</body>
</html>
